//随机测试
class npu_random_test extends npu_base_test;
  `uvm_component_utils(npu_random_test)

  virtual task run_phase(uvm_phase phase);
    int len;
    int16_t a[256], b[256];
    int32_t golden, result;

    phase.raise_objection(this);
    repeat (100) begin
      len = $urandom_range(1, 256);
      for (int i = 0; i < len; i++) begin
        a[i] = $urandom_range(-100, 100);
        b[i] = $urandom_range(-100, 100);
        tb_top.dut.u_top.u_bram.mem[100+i] = {b[i], a[i]};
      end

      write_reg(32'h1000_0000, len << 16 | 1);
      write_reg(32'h1000_0010, 32'h0000_0190);
      write_reg(32'h1000_0014, 32'h0000_0190 + len);
      write_reg(32'h1000_0018, 32'h0000_0500);

      wait_for_done();

      golden = 0;
      for (int i = 0; i < len; i++) golden += a[i] * b[i];
      golden = (golden < 0) ? 0 : golden;
      result = read_mem(200);

      if (result !== golden)
        `uvm_error("RAND", $sformatf("len=%0d, exp=%0d, got=%0d", len, golden, result))
    end
    `uvm_info("RAND", "100 random tests passed!", UVM_LOW)
    phase.drop_objection(this);
  endtask
endclass